<include file="public/shop_header"/>

<body>

<!--main-->
<style type="text/css">
body{ background:#f4f4f4;}
</style>
<div class="cpMain">
  <div class="go-buyAdd">
    <a href="{:U('User/addressList')}" class="choose">{$address.region}{$address.address?:'请填写收货地址'} </a>
  </div>


  <div class="go-buyPro">
    <h3 class="go-buyPro-name">{$config['index_store_name']}</h3>

      <div class="go-buyPro-info clearfix">
        <div class="pic fl">
          <a href="{:U('Goods/goods_detail',array('item_id' => $goods.goods_id))}"><img src="{$goods.original_img}"></a>
        </div>
        <div class="word fr">
          <h3 class="t">
            <a href="{:U('Goods/goods_detail',array('item_id' => $goods.goods_id))}">
              {$goods.goods_name}
            </a>
            <span class="price">
              ￥
              <strong>
                <if condition="$spec_goods_price.price neq ''">
                  {:strtotime($user.vip_time) > time() && $user.vip ? $spec_goods_price.vip_price * $goods_num : $spec_goods_price.price * $goods_num }
                  <else/>
                   {:strtotime($user.vip_time) > time() && $user.vip ? $goods.vip_price * $goods_num : $goods.price * $goods_num }
                </if>
              </strong>
            </span>
          </h3>
          <div class="f clearfix">
            <span class="guig fl">{$spec_goods_price.key_name}</span>
            <span class="num fr">X{$goods_num}</span>
          </div>
        </div>
      </div>


  </div>

  <form id="order">
    <!--地址id-->
    <input type="hidden" name="address_id" value="{$address.address_id}">
    <!--配送方式-->
    <input type="hidden" name="distribution_way" id="distribution_way" value="1">
    <!--支付方式-->
    <input type="hidden" name="pay_way" id="pay_way" value="1">
    <!--商品id-->
    <input type="hidden" name="goods_id" value="{$goods.goods_id}" >
    <!--规格id-->
    <input type="hidden" name="goods_spec" value="{$spec_goods_price.key}" >
    <!--购买的数量-->
    <input type="hidden" name="goods_num" value="{$goods_num}" >
    <div class="porder-detaSpec">
      <dl class="clearfix">
        <dt>配送方式</dt>
        <dd><a href="javascript:;" class="courier-btn" id="distribution">快递邮寄</a></dd>
      </dl>
      <dl class="clearfix" id="distribution_fy">
        <dt>快递费用</dt>
        <dd><span class="c-orange">商家包邮</span></dd>
      </dl>
      <dl class="clearfix">
        <dt>备注留言：</dt>
        <dd>
          <input type="text" class="inpt" name="user_note">
        </dd>
      </dl>
    </div>
  </form>
  <!--<div class="porder-detaReal clearfix">-->
    <!--<div class="dt fl">-->
      <!--代金券-->
    <!--</div>-->
    <!--<div class="dd fr">-->
      <!--<a href="javascript:;" class="vouchers-btn">不适用代金券</a>-->
    <!--</div>-->
  <!--</div>-->
  <div class="porder-detaSpec">
    <dl class="clearfix">
      <dt>积分价格</dt>
      <dd>
        <!--有规格-->
        <if condition="$spec_goods_price.price neq ''">
          {:strtotime($user.vip_time) > time() && $user.vip ? $spec_goods_price.vip_price * $goods_num * 10 : $spec_goods_price.price * $goods_num * 10}积分
          <else/>
          {:strtotime($user.vip_time) > time() && $user.vip ? $goods.vip_price * $goods_num * 10: $goods.price * $goods_num * 10}积分
        </if>

      </dd>
    </dl>
    <dl class="clearfix">
      <dt>商品价格</dt>
      <dd><span class="c-orange">￥
        <if condition="$spec_goods_price.price neq ''">
            {:strtotime($user.vip_time) > time() && $user.vip ? $spec_goods_price.vip_price * $goods_num : $spec_goods_price.price * $goods_num }
          <else/>
            {:strtotime($user.vip_time) > time() && $user.vip ? $goods.vip_price * $goods_num : $goods.price * $goods_num }
        </if>
      </span></dd>
    </dl>
    <dl class="clearfix" id="yf">
      <dt>运  费</dt>
      <dd><span class="c-orange">商家包邮</span></dd>
    </dl>
  </div>
  <div class="go-buySave">
    <a href="javascript:;" class="s-btn">
      立即付款￥
      <strong>
        <if condition="$spec_goods_price.price neq ''">
          {:strtotime($user.vip_time) > time() && $user.vip ? $spec_goods_price.vip_price * $goods_num : $spec_goods_price.price * $goods_num }
          <else/>
          {:strtotime($user.vip_time) > time() && $user.vip ? $goods.vip_price * $goods_num : $goods.price * $goods_num }
        </if>
      </strong>
      ，提交订单
    </a>
  </div>
</div>
<!--main End--> 

<!--选择快递-弹出层-->
<div class="pProduct-pupMarsk" >
</div>
<div class="pProduct-pup" id="courier-pup">
  <a href="javascript:;" class="close iconfont">&#xe6c5;</a>
  <div class="courier-pup-tit">
    配送方式
  </div>
  <div class="courier-pup-list">
    <dl class="clearfix">
      <dt>快递邮寄</dt>
      <dd>
        <div class="arge">
          <input type="radio" name="distribution" id="distribution2" onclick="tab_courier(1)"  checked >
          <label for="distribution2"></label>
        </div>
      </dd>
    </dl>
    <dl class="clearfix">
      <dt>到店自取</dt>
      <dd>
        <div class="arge">
          <input type="radio" name="distribution" id="distribution1" onclick="tab_courier(2)">
          <label for="distribution1"></label>
        </div>
      </dd>
    </dl>

  </div>
  <div class="pProduct-pupButton">
    <a href="javascript:;" class="btn" onclick="conceal()">确   定</a>
  </div>
</div>
<!--选择快递-弹出层 End--> 

<!--选择支付方式-弹出层-->
<div class="pProduct-pupMarsk" >
</div>
<div class="pProduct-pup" id="payment-pup">
  <a href="javascript:;" class="close iconfont">&#xe6c5;</a>
  <div class="courier-pup-tit">
    支付方式
  </div>
  <div class="courier-pup-list">
    <dl class="clearfix">
      <dt>微信支付</dt>
      <dd>
        <div class="arge">
          <input type="radio" name="pay_way" id="pay1" onclick="tab_pay(1)" checked>
          <label for="pay1"></label>
        </div>
      </dd>
    </dl>
    <dl class="clearfix">
      <dt>积分</dt>
      <dd>
        <div class="arge">
          <input type="radio" name="pay_way" id="pay2" onclick="tab_pay(2)">
          <label for="pay2"></label>
        </div>
      </dd>
    </dl>
    <dl class="clearfix">
      <dt>微信+积分支付</dt>
      <dd>
        <div class="arge">
          <input type="radio" name="pay_way" id="pay3" onclick="tab_pay(3)">
          <label for="pay3"></label>
        </div>
      </dd>
    </dl>
  </div>
  <div class="pProduct-pupButton">
    <a href="javascript:;" class="btn" onclick="confirm_shop_order()">确   定</a>
  </div>
</div>
<!--选择支付方式-弹出层 End-->

<script>
  //点击确认隐藏
  function conceal(){
      $(".pProduct-pupMarsk").hide();
      $("#pProduct-pup").hide();
      $("#courier-pup").hide();
      $("#payment-pup").hide();
      $('html').css({"overflow-y":"auto"});
  }

  //快递切换
  function tab_courier(status){
    if (status == 1){ //快递邮寄
        $("#distribution_way").val(1); //赋值
        $("#distribution").html('快递邮寄'); //赋值
        $("#distribution_fy").show(); //显示快递费用
        $("#yf").show(); //显示运费

    }

    if (status == 2){ //自取
        $("#distribution_way").val(2); //赋值
        $("#distribution").html('到店自取'); //赋值
        $("#distribution_fy").hide(); //显示快递费用
        $("#yf").hide(); //显示运费
    }
  }

  //支付方式切换
  function tab_pay(status){
      if (status == 1){ //微信支付
          $("#pay_way").val(1); //赋值
      }
      if (status == 2){ //积分支付
          $("#pay_way").val(2); //赋值
      }
      if (status == 3){ //微信+积分支付
          $("#pay_way").val(3); //赋值
      }
  }

  //订单提交支付
  function confirm_shop_order() {
      $.ajax({
          type : "POST",
          url:"/home/payment/confirm_add_order.html",
          data : $('#order').serialize(),// 你的formid 搜索表单 序列化提交
          dataType:'json',
          success: function(result){
              if (result.status == 200){
                  //还需要支付，调取微信支付
                  function onBridgeReady(){
                      WeixinJSBridge.invoke(
                          'getBrandWCPayRequest', {
                              "appId":result.result.appId,     //公众号名称，由商户传入
                              "timeStamp":result.result.timeStamp,         //时间戳，自1970年以来的秒数
                              "nonceStr":result.result.nonceStr, //随机串
                              "package":result.result.package,
                              "signType":"MD5",         //微信签名方式：
                              "paySign":result.result.paySign //微信签名
                          },
                          function(res){
                              if(res.err_msg == "get_brand_wcpay_request:ok" ){
                                  location.href = '/home/order/shop_index.html';
                              }
                              if(res.err_msg == "get_brand_wcpay_request:cancel" ){
                                  location.href = '/home/order/shop_index.html';
                              }
                              if(res.err_msg == "get_brand_wcpay_request:fail" ){
                                  location.href = '/home/order/shop_index.html';
                              }
                          });
                  }
                  if (typeof WeixinJSBridge == "undefined"){
                      if( document.addEventListener ){
                          document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                      }else if (document.attachEvent){
                          document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                          document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                      }
                  }else{
                      onBridgeReady();
                  }
              }else{
                  if (result.status == 400){
                      //支付成功
                      layer.msg(result.msg,{icon:1,time:2000},function(){if(result.url){ window.location.href = result.url;}});
                  }else{
                      //遇到错误
                      layer.msg(result.msg,{icon:2,time:2000},function(){if(result.url){ window.location.href = result.url;}});
                  }
              }
          }
      });
  }


</script>

</body>
</html>
